<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '审批'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="140px">

    <el-form-item label="申请人编号" prop="applyNo" >
      <el-input v-model="dataForm.applyNo" placeholder="申请人编号" :disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="申请人姓名" prop="applyName">
      <el-input v-model="dataForm.applyName" placeholder="申请人姓名" :disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="申请人类别" prop="applyType">
      <el-input v-model="dataForm.applyType" placeholder="申请人类别" :disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="申请权限" prop="applyPrivilege">
      <el-input v-model="dataForm.applyPrivilege" placeholder="申请权限" :disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="申请原因" prop="applyReason">
      <el-input v-model="dataForm.applyReason" placeholder="申请原因" :disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="审批意见" prop="auditResult">
      <!-- <el-input v-model="dataForm.auditResult" placeholder="审批意见"></el-input> -->
      <el-switch
  v-model="dataForm.auditResult"
  style="display: block"
  active-color="#13ce66"
  inactive-color="#ff4949"
  active-text="通过"
  inactive-text="不通过">
</el-switch>
    </el-form-item>
    <el-form-item label="审批备注" prop="auditRemark">
      <el-input v-model="dataForm.auditRemark" type="textarea"
  :rows="3"
  placeholder="请输入内容"></el-input>
    </el-form-item>
    <el-form-item label="审批状态" prop="auditStatus">
      <el-input v-model="dataForm.auditStatus" placeholder="审批状态" :disabled="true"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          gmtCreate: '',
          createBy: '',
          gmtModified: '',
          lastModifiedBy: '',
          isDeleted: '',
          sortNo: '',
          version: '',
          applyNo: '',
          applyName: '',
          applyType: '',
          applyPrivilege: '',
          applyReason: '',
          auditResult: 'false',
          auditRemark: '',
          auditStatus: ''
        },
        dataRule: {
          gmtCreate: [
            { required: true, message: '记录创建时间不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '记录创建者不能为空', trigger: 'blur' }
          ],
          gmtModified: [
            { required: true, message: '记录更新时间不能为空', trigger: 'blur' }
          ],
          lastModifiedBy: [
            { required: true, message: '记录最后更新人不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(1删除,0未删除)不能为空', trigger: 'blur' }
          ],
          sortNo: [
            { required: true, message: '序号不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/authority/tidentifyaudit/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.gmtCreate = data.tIdentifyAudit.gmtCreate
                this.dataForm.createBy = data.tIdentifyAudit.createBy
                this.dataForm.gmtModified = data.tIdentifyAudit.gmtModified
                this.dataForm.lastModifiedBy = data.tIdentifyAudit.lastModifiedBy
                this.dataForm.isDeleted = data.tIdentifyAudit.isDeleted
                this.dataForm.sortNo = data.tIdentifyAudit.sortNo
                this.dataForm.version = data.tIdentifyAudit.version
                this.dataForm.applyNo = data.tIdentifyAudit.applyNo
                this.dataForm.applyName = data.tIdentifyAudit.applyName
                this.dataForm.applyType = data.tIdentifyAudit.applyType
                this.dataForm.applyPrivilege = data.tIdentifyAudit.applyPrivilege
                this.dataForm.applyReason = data.tIdentifyAudit.applyReason
                this.dataForm.auditResult = data.tIdentifyAudit.auditResult === '通过' ? true : false
                this.dataForm.auditRemark = data.tIdentifyAudit.auditRemark
                this.dataForm.auditStatus = data.tIdentifyAudit.auditStatus
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/authority/tidentifyaudit/${!this.dataForm.id ? 'save' : 'audit'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'gmtCreate': this.dataForm.gmtCreate,
                'createBy': this.dataForm.createBy,
                'gmtModified': this.dataForm.gmtModified,
                'lastModifiedBy': this.dataForm.lastModifiedBy,
                'isDeleted': this.dataForm.isDeleted,
                'sortNo': this.dataForm.sortNo,
                'version': this.dataForm.version,
                'applyNo': this.dataForm.applyNo,
                'applyName': this.dataForm.applyName,
                'applyType': this.dataForm.applyType,
                'applyPrivilege': this.dataForm.applyPrivilege,
                'applyReason': this.dataForm.applyReason,
                'auditResult': this.dataForm.auditResult,
                'auditRemark': this.dataForm.auditRemark,
                'auditStatus': this.dataForm.auditStatus
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
